package com.example.springboot_sp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.springboot_sp.controller.dto.UserPasswordDTO;
import com.example.springboot_sp.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 郭守军
 * @since 2022-08-18
 */
public interface UserMapper extends BaseMapper<User> {

    @Update("update sys_user set password = #{newPassword} where username = #{username} and password = #{password}")
    int updatePassword(UserPasswordDTO userPasswordDTO);

    @Select("select count(*) from sys_user where username like #{username} " )
    Integer selectTotal(@Param("username")String username);

    @Select("select u.* from article a left join sys_user u on a.userid = u.id where a.id = #{articleId} ")
    User findUserByArticleId(@Param("articleId")  Integer articleId);

    @Select("select count(*) count, u.* from sys_user u left join  article a on a.user = u.nickname where u.id = #{userId}  ")
    User allInforOfUser(@Param("userId")  Integer userId);

    //按id的倒序挑五个人
    @Select("select u.* from sys_user u order by id asc limit 5")
    List<User> limitFiveUser();

    //    查询浏览次数
    @Select("select SUM(a.readnumber) from article a  left join sys_user u on a.userid = u.id where u.id = #{id}")
    Integer findReadNumber(@Param("id") Integer id);
    //查询被收藏数量
    @Select("SELECT count(*) FROM t_collection c left join  sys_user u on u.id = c.userid where u.id = #{id}")
    Integer findCollectionNumber(@Param("id") Integer id);
}
